<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户列表</title>
    <link type="text/css" rel="stylesheet" href="layui/css/layui.css">
    <script type="text/javascript" src="layui/layui.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        var layer;
        layui.use('layer', function(){
            layer = layui.layer;
        });
        function openAdd() {
            layer.open({
                type: 2,
                area: ['500px', '350px'],
                content: '/page/user-add.html'
            });
        }
        function deleteUser(id){
            if(confirm("是否删除？"))
                axios.delete("/user/"+id).
                then(function (value) {
                    location.reload();
                })
        }
    </script>
</head>
<body>
    <button class="layui-btn layui-btn-normal" onclick="openAdd()">添加用户</button>
    <table class="layui-table">
        <thead>
            <tr>
                <th>编号</th>
                <th>账号</th>
                <th>密码</th>
                <th>类型</th>
                <th>图片</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <tr th:each="user:${users}">
                <td th:text="${user.userId}"></td>
                <td th:text="${user.userName}"></td>
                <td th:text="${user.userPwd}"></td>
                <td th:text="${user.userType}"></td>
                <td>
                    <img th:src="@{${user.userImg}}">
                </td>
                <td>
                    <button type="button"
                            th:onclick="javascript:location.href='/user/[[${user.userId}]]'" class="layui-btn layui-btn-primary layui-btn-sm">
                        <i class="layui-icon">&#xe642;</i>
                    </button>
                    <button type="button"
                            th:onclick="deleteUser([[${user.userId}]])"
                            class="layui-btn layui-btn-primary layui-btn-sm">
                        <i class="layui-icon">&#xe640;</i>
                    </button>
                </td>
            </tr>
        </tbody>
    </table>
</body>
</html>